package com.example.apple.tianqiyubaoone;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;

/**
 * Created by apple on 17/3/6.
 */
public class SetCityeActivity extends Activity {
    Button 输入返回,输入确定;
    SharedPreferences preferences;
    EditText 输入城市;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setcitye);
        输入返回 =(Button) findViewById(R.id.输入返回);
        输入确定 =(Button) findViewById(R.id.输入确定);
        输入返回.setOnClickListener(new  setUpcitye());
        输入确定.setOnClickListener(new setUpcitye());
        输入城市 =(EditText) findViewById(R.id.输入城市);
        preferences = getSharedPreferences("met",Activity.MODE_PRIVATE);
    }

    private class setUpcitye implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.输入返回:
                    finish();
                    break;
                case R.id.输入确定:
                    saveCityName();
                    break;
            }
        }
    }
    void intntStartActivity(){
        MainActivity.maina.finish();
        Intent intent = new Intent();
        intent.setClass(getWindow().getContext(), MainActivity.class);
        startActivity(intent);
        finish();
    }
    private void saveCityName() {
        if (输入城市.getText().toString().equals("u")){
            Toast.makeText(SetCityeActivity.this,"文本框不能无内容",Toast.LENGTH_SHORT).show();
        }else {
            SharedPreferences.Editor ediotr = preferences.edit();
            ediotr.putString("city",输入城市.getText().toString());
            ediotr.commit();
            Log.e("－－－>输入城市",输入城市.getText().toString());
            intntStartActivity();
        }
    }
}
